﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-27-21:47
//  * @Description:
//  */

using Code.GameLogic.BaseClass;
using Unity.VisualScripting;
using UnityEngine;

namespace Code.GameLogic.Map.Controller
{
    public class PlaceBlockController : AbsGameLogicController<PlaceBlockBo, MapManager>
    {
        private SpriteRenderer _spriteRenderer;

        private StateEnum _stateEnum;
        
        public override void InitGo(PlaceBlockBo bo)
        {
            _spriteRenderer = this.AddComponent<SpriteRenderer>();
            _spriteRenderer.sprite = Resources.Load<Sprite>("地图/地块/放置图");
            _spriteRenderer.sortingOrder = 1;
            transform.localPosition = new Vector3(0, 0, 0); // 设置位置
            transform.localScale = new Vector3(1, 1, 1); // 设置缩放
            SetStateEnum(StateEnum.Hide);

        }



        private void Update()
        {
            SwitchState(_stateEnum);

        }

        public void SetStateEnum(StateEnum stateEnum)
        {
            _stateEnum = stateEnum;
        }
        

        private void SwitchState(StateEnum stateEnum)
        {
            if (StateEnum.Hide == stateEnum)
            {
                _spriteRenderer.enabled = false;
            }
            else if (StateEnum.ShowXianJianPlace == stateEnum && 0 == bo.Type)
            {
                _spriteRenderer.color = Color.cyan;
                _spriteRenderer.enabled = true;
            }
            else if (StateEnum.ShowMonsterPlace == stateEnum && 2 == bo.Type)
            {
                _spriteRenderer.color = Color.yellow;
                _spriteRenderer.enabled = true;
            }
            else if (StateEnum.ShowDeny == stateEnum)
            {
                _spriteRenderer.color = Color.red;
                _spriteRenderer.enabled = true;
            }
            else if (StateEnum.ShowAllow == stateEnum)
            {
                _spriteRenderer.color = Color.green;
                _spriteRenderer.enabled = true;
            }
            else
            {
                _spriteRenderer.enabled = false;
            }
        }

        public enum StateEnum
        {
            Hide,
            ShowXianJianPlace,
            ShowMonsterPlace,
            ShowDeny,
            ShowAllow
        }
    }
}